home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / DRAGON.ZIP / dragon / dragon.inc next >
Encoding:
Text File  |  1997-07-18  |  3.3 KB  |  142 lines

  1. #ifndef (DRAGON_ANGLE)
  2.    #declare DRAGON_ANGLE = 90
  3. #end
  4.  
  5. #ifndef (DRAGON_SHAPE)
  6.    #declare DRAGON_SHAPE =
  7.    union {
  8.       cylinder { <0, 0, 0>, <1, 0, 0>, 0.1 }
  9.       sphere { <0, 0, 0>, 0.1 }
  10.       sphere { <1, 0, 0>, 0.1 }
  11.    }
  12. #end
  13.  
  14. #ifndef (DRAGON_DEPTH)
  15.    #declare DRAGON_DEPTH = 3
  16. #else
  17.    #declare DRAGON_DEPTH = int(abs(DRAGON_DEPTH))
  18. #end
  19.  
  20.  
  21.  
  22. /*
  23.  * compute the bending-order
  24.  */
  25.  
  26. #if (DRAGON_DEPTH > 0)
  27.    #declare DRAGON_BENDSTRING = "L"
  28.    #declare DRAGON_DEPTH = DRAGON_DEPTH - 1
  29. #else
  30.    #declare DRAGON_BENDSTRING = ""
  31. #end
  32.  
  33. #declare DRAGON_ISODD = 0
  34. #declare DRAGON_NUMBENDS = DRAGON_DEPTH
  35.  
  36. #while (DRAGON_NUMBENDS>0)
  37.  
  38.    #declare DRAGON_REVERSE = ""
  39.    #declare DRAGON_LEN = strlen(DRAGON_BENDSTRING)
  40.    #declare DRAGON_STRCNT = 1
  41.  
  42.    #while (DRAGON_STRCNT<DRAGON_LEN+1)
  43.       #declare DRAGON_CHAR = substr(DRAGON_BENDSTRING, DRAGON_STRCNT, 1)
  44.       #if ( strcmp(DRAGON_CHAR,"R") = 0 )
  45.          #declare DRAGON_REVERSE = concat("L", DRAGON_REVERSE)
  46.       #else
  47.          #declare DRAGON_REVERSE = concat("R", DRAGON_REVERSE)
  48.       #end
  49.       #declare DRAGON_STRCNT = DRAGON_STRCNT + 1
  50.    #end
  51.  
  52.  
  53.    #if (DRAGON_ISODD=0)
  54.       #declare DRAGON_BENDSTRING = concat(DRAGON_REVERSE, "R", DRAGON_BENDSTRING)
  55.    #else
  56.       #declare DRAGON_BENDSTRING = concat(DRAGON_BENDSTRING, "L", DRAGON_REVERSE)
  57.    #end
  58.  
  59.    #declare DRAGON_ISODD = 1 - DRAGON_ISODD
  60.    #declare DRAGON_NUMBENDS = DRAGON_NUMBENDS - 1
  61. #end
  62.  
  63. #debug concat("\nDRAGON_BENDSTRING is \"", DRAGON_BENDSTRING, "\"\n")
  64.  
  65.  
  66.  
  67. /*
  68.  * now build the dragon-union
  69.  */
  70.  
  71. #declare DRAGON_NUMTRANS = strlen(DRAGON_BENDSTRING)
  72.  
  73. #ifndef (DRAGON_FROM)
  74.    #declare DRAGON_FROM = 0
  75. #else
  76.    #declare DRAGON_FROM = int(abs(DRAGON_FROM))
  77. #end
  78. #declare DRAGON_FROM_TMP = DRAGON_FROM
  79.  
  80. #ifndef (DRAGON_UPTO)
  81.    #declare DRAGON_UPTO = DRAGON_NUMTRANS
  82. #else
  83.    #declare DRAGON_UPTO = int(abs(DRAGON_UPTO))
  84. #end
  85. #declare DRAGON_UPTO_TMP = DRAGON_UPTO
  86.  
  87. #declare DRAGON_STRCNT = 1
  88.  
  89. #declare DRAGON_LASTX = 0
  90. #declare DRAGON_LASTY = 0
  91. #declare DRAGON_ROTANGLE = 0
  92.  
  93. union {
  94.    #if (DRAGON_FROM = 0)
  95.       object {
  96.          DRAGON_SHAPE
  97.       }
  98.       #declare DRAGON_LASTX = 1
  99.       #declare DRAGON_LASTY = 0
  100.    #end
  101.    #while (DRAGON_NUMTRANS > 0)
  102.       #declare DRAGON_CHAR = substr(DRAGON_BENDSTRING, DRAGON_STRCNT, 1)
  103.       #debug concat(DRAGON_CHAR)
  104.  
  105.       #if ( strcmp(DRAGON_CHAR,"R") = 0 )
  106.          #declare DRAGON_ROTANGLE = DRAGON_ROTANGLE + DRAGON_ANGLE
  107.       #else
  108.          #declare DRAGON_ROTANGLE = DRAGON_ROTANGLE - DRAGON_ANGLE
  109.       #end
  110.  
  111.       #if (DRAGON_ROTANGLE = 0)
  112.          #declare DRAGON_RADANGLE = 0
  113.       #else
  114.          #declare DRAGON_RADANGLE = pi/(180/DRAGON_ROTANGLE)
  115.       #end
  116.  
  117.       #declare DRAGON_NEWX = DRAGON_LASTX + ( cos(DRAGON_RADANGLE) )
  118.       #declare DRAGON_NEWY = DRAGON_LASTY + ( sin(DRAGON_RADANGLE) )
  119.  
  120.       #if (DRAGON_FROM <= DRAGON_STRCNT)
  121.          object {
  122.             DRAGON_SHAPE
  123.             rotate <0, 0, DRAGON_ROTANGLE>
  124.             translate <DRAGON_LASTX, DRAGON_LASTY, 0>
  125.          }
  126.       #end
  127.  
  128.       #declare DRAGON_LASTX = DRAGON_NEWX
  129.       #declare DRAGON_LASTY = DRAGON_NEWY
  130.       #declare DRAGON_STRCNT = DRAGON_STRCNT + 1
  131.       #declare DRAGON_NUMTRANS = DRAGON_NUMTRANS - 1
  132.       #declare DRAGON_UPTO = DRAGON_UPTO - 1
  133.       #if (DRAGON_UPTO <= 0)
  134.          #declare DRAGON_NUMTRANS = 0
  135.       #end
  136.    #end
  137.  
  138. }
  139.  
  140. #declare DRAGON_FROM = DRAGON_FROM_TMP
  141. #declare DRAGON_UPTO = DRAGON_UPTO_TMP
  142.